package com.fyyg.common.util;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * @author hang.ouyang
 * @date 2016-04-07 9:08
 */
public class PropertiesUtil {
    private final static Logger logger = LogManager.getLogger();

    public static Properties getProperties(String propFileName){
        Properties properties = new Properties();
        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
        try(InputStream inputStream = classLoader.getResourceAsStream(propFileName)){
            properties.load(inputStream);
        }catch (IOException e) {
            logger.error("load properties\t"+propFileName+"\tfail "+e.getLocalizedMessage());
        }
        return properties;
    }

    public static Object getPropertiesValue(String propFileName, String propertiesKey) {
       return getProperties(propFileName).get(propertiesKey);
    }

}
